package Test5;

import java.util.Scanner;

public class PhoneTest {
    public static void main(String[] args) {
        //需求：
        //定义数组存储3部手机对象
        //手机的属性：品牌，价格，颜色
        //要求，计算出三部手机的平均价格

        //1.定义数组
        Phone[] arr = new Phone[3];

        //2.创建对象
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第" + (i + 1) + "辆手机的品牌：");
            String brand = sc.next();
            System.out.println("请输入第" + (i + 1) + "辆手机的价格：");
            int price = sc.nextInt();
            System.out.println("请输入第" + (i + 1) + "辆手机的颜色：");
            String color = sc.next();
            Phone phone = new Phone(brand, price, color);
            arr[i] = phone;
        }

        //3.遍历数组
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i].getPrice();
        }

        //4.输出每一部手机的信息
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i].getBrand() + "," + arr[i].getPrice() + "," + arr[i].getColor());
        }

        //5.输出手机平均价格
        //数据能不写死，尽量不写死
        //int avg = sum / arr.length

        double avg1 = sum * 1.0 / arr.length;
        System.out.println("手机的平均价格为：" + avg1);
    }
}
